package cn.onecloud.tablet.xiaozhi.net;

import com.freerdp.freerdpcore.utils.Log;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;


/**
 * Created by yin.he on 17-11-17.
 */

public class FeedBackAppc {


    public static void feedbackToAPPCC(String uuid, boolean isSuccess) {
        String message = isSuccess ? "" : "login fail";
        String data = "{\"action\": \"login_fb\", \"success\": " + isSuccess + ", \"message\": \"" + message + "\"}";
        try {
            String httpUrl = "http://appcc.cloudak47.com/connection/feedback/send?key=" + uuid + "&data=" + URLEncoder.encode(data, "UTF-8") + ")";
            Log.d(FeedBackAppc.class.getName(), httpUrl);
            URL url = new URL(httpUrl);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("GET");
            connection.setReadTimeout(1000 * 60 * 1);
            connection.setConnectTimeout(1000 * 60 * 1);
            connection.connect();

            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            String line = null;
            StringBuffer stringBuffer = new StringBuffer();
            while ((line = bufferedReader.readLine()) != null) {
                line = new String(line.getBytes("UTF-8"));
                stringBuffer.append(line);
            }
            Log.d(FeedBackAppc.class.getName(), stringBuffer.toString());
            bufferedReader.close();
            connection.disconnect();
        } catch (Exception e) {
            e.printStackTrace();
            String msg = "Error in feedback login result to APPCC. uuid=" + uuid + ", isSuccess=" + isSuccess;
            Log.d(FeedBackAppc.class.getName(), msg);
        }
    }
}
